package com.rs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rs.dao.ZhAskForMapper;
import com.rs.dao.ZhAttendanceMapper;
//import com.rs.dao.ZhAttendanceRulesMapper;
import com.rs.model.ZhAskFor;
//import com.rs.model.ZhAttendance;
//import com.rs.model.ZhAttendanceRules;
import com.rs.service.ZhAskforSercive;
//import com.rs.util.TimerTest;

@Service
@Transactional
public class ZhAskforSerciveImpl implements ZhAskforSercive {
	@Autowired
	private ZhAskForMapper afm;
	@Autowired
	private ZhAttendanceMapper am;
//	@Autowired
//	private ZhAttendanceRulesMapper arDao;
	@Override
	public void askforAdd(ZhAskFor askfor) {
		
		afm.insert(askfor);
	}

	@Override
	public List<ZhAskFor> askforSelectAll() {
		
		return afm.askforselectAll();
	}

	@Override
	public PageInfo<ZhAskFor> askforSelectByTiaojian(ZhAskFor askfor) {
		PageHelper.startPage(askfor.getPageNum(), 10);
		List<ZhAskFor> list = afm.askforSelectByTiaojian(askfor);
		PageInfo<ZhAskFor> pageinfo = new PageInfo<>(list);
		return pageinfo;
	}

	@Override
	public void askforUpDate(ZhAskFor askfor) {
		
		afm.updateByPrimaryKey(askfor);
	}

	@Override
	public ZhAskFor askforSelectById(int ask_id) {
		
		return afm.selectByPrimaryKey(ask_id);
	}

	@Override
	public void askforDel(int ask_id) {
		
		afm.selectByPrimaryKey(ask_id);
	}

	@Override
	public void askforToExamine(ZhAskFor askfor) {
		
		//创建一个打卡记录的实体类
//		ZhAttendance aa = new ZhAttendance();
//		//创建四个打卡状态
//		int at_amtype = 0;
//		int at_noontype = 0;
//		int at_pmtype = 0;
//		int at_nighttype = 0;
//		//查看打卡规则
//		ZhAttendanceRules ra = arDao.rarSelectAll();
//		//为打卡状态赋值
//		if(ra.getAtru_am().equals("No clock in")){
//			at_amtype = -1;
//		}else {
//			at_amtype = 6;
//		}
//		if(ra.getAtru_noon().equals("No clock in")){
//			at_noontype = -1;
//		}else {
//			at_noontype = 6;
//		}
//		if(ra.getAtru_pm().equals("No clock in")){
//			at_pmtype = -1;
//		}else {
//			at_pmtype = 6;
//		}
//		if(ra.getAtru_night().equals("No clock in")){
//			at_nighttype = -1;
//		}else {
//			at_nighttype = 6;
//		}
//		//获取请假是否通过
//		int a = askfor.getAsk_audit();
//		//获取请假记录的主键
//		int ask_id = askfor.getAsk_id();
//		//如果请假不通过，修改状态
//			if(a==2) {
//				afm.updateByPrimaryKey(askfor);
//				return;
//			}
//		//如果请假通过新增或修改打卡记录
//			else{
//					afm.updateByPrimaryKey(askfor);//修改状态
//					ZhAskFor a1 = afm.selectByPrimaryKey(ask_id);//查看这条请假记录
//					//获取请假的时间节点 
//					String ask_ktimes = a1.getAsk_ktime()+"";
//					String ask_jtimes = a1.getAsk_jtime()+"";
//					//获取请假天数
//					double ask_days = a1.getAsk_days();
//					//调用工具类获取休息的日期
//					TimerTest tt = new TimerTest();
//					try {
//						//获取休息日期的集合
//						List<String> ll = tt.dateNumber(a1);
//						//新增空的打卡记录
//						for(String l1:ll){
//							aa.setAt_uid(a1.getAsk_uid());
//							aa.setAt_days(l1);
//							ZhAttendance a2 = am.attendanceSelectByDay(aa);
//							if(null!=a2) {
//								break;
//							}else{
//								am.attendanceAdd1(aa);
//							}
//						}
//						//根据请假日期更改打卡记录
//						for(String l1:ll){
//							aa=null;
//							aa.setAt_uid(a1.getAsk_uid());
//							aa.setAt_days(l1);
////							Attendance a2 = am.attendanceSelectByDay(aa);
////							if(null!=a2){
//								if(ask_ktimes.equals(l1+" 07:00:00")){
//									if(ask_days<1){
//										aa.setAt_amtype(at_amtype);
//										aa.setAt_noontype(at_noontype);
//										am.attendanceUpDate1(aa);
//									}else if(ask_days>=1){
//										aa.setAt_amtype(at_amtype);
//										aa.setAt_noontype(at_noontype);
//										aa.setAt_pmtype(at_pmtype);
//										aa.setAt_nighttype(at_nighttype);
//										am.attendanceUpDate1(aa);
//									}
//								}else if(ask_ktimes.equals(l1+" 13:00:00")){
//										aa.setAt_pmtype(at_pmtype);
//										aa.setAt_nighttype(at_nighttype);
//										am.attendanceUpDate1(aa);
//								}else{
//									if(ask_jtimes.equals(l1+" 13:00:00")){
//										aa.setAt_amtype(at_amtype);
//										aa.setAt_noontype(at_noontype);
//										am.attendanceUpDate1(aa);
//									}else{
//										aa.setAt_amtype(at_amtype);
//										aa.setAt_noontype(at_noontype);
//										aa.setAt_pmtype(at_pmtype);
//										aa.setAt_nighttype(at_nighttype);
//										am.attendanceUpDate1(aa);
//									}
//								}        
////						    }
//						}
//					} catch (Exception e) {
//						
//						e.printStackTrace();
//					}
//			}
	}

	
}
